package com.dbMethod;

import com.lUtils.jdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class sql_QueryMoney {
    /**
     * 查找账户余额
     * @param CardId 卡号
     * @return 账户余额
     */
    public static int QueryMoney(String CardId) {

        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int balance=0;
        try{
            con= jdbcUtils.getConnection();
            ps=con.prepareStatement("select balance from cardinfo where cardID =?");
            ps.setString(1,CardId);
            rs=ps.executeQuery();
            if(rs.next()){
                 balance=rs.getInt("balance");
            }
            return  balance;

        }catch (SQLException e){
            e.printStackTrace();
        }
        finally {
            jdbcUtils.closeTheStream(rs, ps, con);
            return  balance;
        }
    }
}
